package com.qing.cheng.controller;


import com.qing.cheng.dto.ExceptionRes;
import com.qing.cheng.dto.RegisterDto;
import com.qing.cheng.dto.ResponseMessage;
import com.qing.cheng.dto.SuccessRes;
import com.qing.cheng.service.RegisterService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 注册
 */
@RestController
@RequestMapping("/userInfo")
public class RegisterController {

    Logger log = LoggerFactory.getLogger(RestController.class);

    private final RegisterService registerService;


    public RegisterController(RegisterService registerService) {
        this.registerService = registerService;
    }


    /**
     * 注册账户
     * @param registerDto 用户对象
     * @return
     */
    @RequestMapping("/register")
    public ResponseMessage register(@RequestBody RegisterDto registerDto) {
        try {
            return SuccessRes.success(registerService.register(registerDto));
        }catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            return ExceptionRes.Fail(e);
        }
    }
}
